package com.jxj.GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class shouyeGUI {
    newmain n1 = new newmain();

    public void shouGUI(JPanel shouyepanel) {
        shouyepanel.setLayout(null);
        JButton jButton = new JButton("点击启动聊天");
        jButton.setBounds(40, 600, 150, 30);
        n1.changeButton(jButton);
        shouyepanel.add(jButton);
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ChatClient client = new ChatClient();
                client.app();
            }
        });
        JLabel top = new JLabel("本月每日跑步公里数统计图");
        top.setBounds(40, 0, 250, 50);
        Font font = new Font("微软雅黑", Font.BOLD, 16); // 字体、样式和大小
        top.setFont(font);
        shouyepanel.add(top);
        JPanel tu = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                drawChart(g);
            }
        };
        tu.setBounds(40, 50, 1400, 250);
        shouyepanel.add(tu);

        JLabel top1 = new JLabel("本月每日跑步人数统计图");
        top1.setBounds(40, 300, 250, 50);
        Font font1 = new Font("微软雅黑", Font.BOLD, 16); // 字体、样式和大小
        top1.setFont(font);
        shouyepanel.add(top1);
        JPanel tu1 = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                drawChart2(g);
            }
        };
        tu1.setBounds(40, 360, 1400, 250);
        shouyepanel.add(tu1);

    }


    // 绘制统计图
    private void drawChart(Graphics g) {
        Random random = new Random();
        int[] data = new int[30];
        // 生成随机数据
        for (int i = 0; i < data.length; i++) {
            data[i] = random.nextInt(100); // 最大值为100公里
        }
        // 绘制柱状图
        int barWidth = 24;
        int startX = 0;
        int startY = 200;

        for (int i = 0; i < data.length; i++) {
            int barHeight = data[i] * 3; // 缩放系数，使得柱状图更加直观
            g.setColor(Color.BLUE);
            g.fillRect(startX + i * (barWidth + 10), startY - barHeight, barWidth, barHeight);
            g.setColor(Color.BLACK);
            g.drawString(String.valueOf(i + 1), startX + i * (barWidth + 10), startY + 20);
        }
    }

    private void drawChart2(Graphics g) {
        Random random = new Random();
        int[] data = new int[30];
        // 生成随机数据
        for (int i = 0; i < data.length; i++) {
            data[i] = random.nextInt(100); // 最大值为100公里
        }
        // 绘制柱状图
        int barWidth = 24;
        int startX = 0;
        int startY = 200;

        for (int i = 0; i < data.length; i++) {
            int barHeight = data[i] * 3; // 缩放系数，使得柱状图更加直观
            g.setColor(Color.RED);
            g.fillRect(startX + i * (barWidth + 10), startY - barHeight, barWidth, barHeight);
            g.setColor(Color.BLACK);
            g.drawString(String.valueOf(i + 1), startX + i * (barWidth + 10), startY + 20);
        }
    }
}
